<template>
  <div class>
    <div
      v-if="showInfo"
      class="cesiumdialog"
      :style="{
        left: winPos[0] - getscalepxcnum(202) + 'px',
        bottom: winPos[3] + 'px',
        width: getscalepxc(410),
        height: getscalepxc(330),
      }"
    >
      <!-- 关闭图标 -->
      <i
        class="el-icon-close"
        :style="{
          position: 'absolute',
          right: getscalepxc(10),
          top: getscalepxc(10),
          fontSize: getscalepxc(12),
          pointerEvents: 'auto',
          cursor: 'pointer',
        }"
        @click="closebox()"
      ></i>
    </div>
  </div>
</template>
<script>
export default {
  name: "basecard",
  components: {},
  data() {
    return {
      showInfo: true,
      winPos: [0, 0, 0, 0],
      _instance: {},
    };
  },
  props: {
    // diahtml: "",
    options: {},
  },
  computed: {},
  watch: {
    showInfo: {
      handler: function (n, o) {
        this.$nextTick(function () {
          // this.initchart();
        });
      },
    },
    winPos: {
      handler: function (n, o) {
        //判断位置与窗口偏移
        let width = document.documentElement.clientWidth;
        let height = document.documentElement.clientHeight;

        let offwidth = n[0];
        let offheight = n[1];

        let reswidth = width - offwidth;
        let resheight = height - offheight;
        if (
          reswidth < 220 ||
          resheight < 20 ||
          reswidth > width ||
          resheight > height
        ) {
          this.showInfo = false;
        } else {
          this.showInfo = true;
        }
      },
    },
  },
  mounted() {
    this.$root._earth.sceneTree.root.children.push({
      ref: this.options.uid,
      czmObject: {
        name: "Pin1",
        xbsjType: "Pin",
        position: this.options.position,
        near: 300,
        // show: true,
        // scale: 0.3,
        // imageUrl: '/configuration/ziyuan/gaojing.png'
      },
    });


    this.$parent.pinarr.push(this.options.uid);
    let pin1 = this.$root._earth.sceneTree.$refs[this.options.uid].czmObject;
    XE.MVVM.track(this, "winPos", pin1, "winPos");
    this.instance = pin1
  },
  methods: {
    closecard() {
      //删除_earth.children对象
      this.$root._earth.sceneTree.root.children.map((eactpin, index) => {
        if (eactpin.ref == this.options.uid) {
          this.$root._earth.sceneTree.root.children[index].destroy();
          this.$root._earth.sceneTree.root.children.splice(index, 1);
        }
      });

      //删除msgbox数组对应元素
      let msgboxarr = _.cloneDeep(this.$parent.cardnew);
      msgboxarr.map((item, index) => {
        if (item.uid == this.options.uid) {
          this.$parent.cardnew.splice(index, 1);
        }
      });
      
      delete this.$parent.pinarrwuxi[this.options.name]
    },
  },
};
</script>
<style lang='scss' scoped>
</style>